//
//  XJStatusListViewModel.m
//  weiboOC
//
//  Created by 徐绩 on 16/4/22.
//  Copyright © 2016年 ayumi. All rights reserved.
//

#import "XJStatusListViewModel.h"
#import "XJUserAccountViewModel.h"
#import "XJNetworkTools.h"

@implementation XJStatusListViewModel

-(void)loadData:(void (^)(BOOL))finishedBlock{

    NSString *urlStr = @"https://api.weibo.com/2/statuses/home_timeline.json";
    
    XJUserAccountViewModel *viewModel = [XJUserAccountViewModel sharedViewModel];

    NSDictionary *params = @{@"access_token":viewModel.accout.access_token};
    
    [[XJNetworkTools sharedTools]request:XJRequestMethodGet urlString:urlStr parameters:params finished:^(NSDictionary * responseObject, NSError *error) {
        
        if (error) {
            Log(@"数据请求错误,%@",error);
            return;
        }
        
        NSArray *array = responseObject[@"statuses"];
        NSMutableArray *arrayM = [NSMutableArray array];
        for (NSDictionary *dict in array) {
            
            XJStatusModel *statusModel = [XJStatusModel statusModelWithDict:dict];
            XJStatusViewModel *statusViewModel = [[XJStatusViewModel alloc]init];
            statusViewModel.statusModel = statusModel;
            [arrayM addObject:statusViewModel];
        }
        self.statusArr = arrayM.copy;
        finishedBlock(YES);
        
    }];
    
}
@end
